<!DOCTYPE html>
<html lang="en">
<head>
    <title>会员状态</title>
    <meta charset="UTF-8">
    <script type="text/javascript" src="lib/jquery-1.12.4.min.js"></script>
    <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="lib/layui/css/layui.css">
    <script type="text/javascript" src="lib/layui/layui.js"></script>
    <script>
        document.write('<script src="lib/lib.js?t=' + new Date().getTime() + '"><\/script\>')
        document.write('<script src="lib/api.js?t=' + new Date().getTime() + '"><\/script\>')
        document.write('<link rel="stylesheet" href="lib/common.css?t=' + new Date().getTime() + '">')
     </script>
     <!--[if lte IE 9]>
    <script type='text/javascript' src='lib/jquery.xdomainrequest.min.js'></script>
    <script type='text/javascript' src='lib/json2.js'></script>
    <![endif]-->
    <style>
       .opStatistics .span6 span:first-child{
        display: inline-block;
        width: 60%;
        text-align: right;
       }
       .companyInfoBox label{
        display: inline-block;
        width: 25%;
        text-align: right;
       }
       .companyInfoBox input{
        width: 65%;
       }
    </style>
</head>
<body>
    <div id="infoBox">
        <div id="userBox" style="display: none;">
            <div class="row-fluid" style="padding-top: 10px;">
                <div class="span2" style="text-align: center;padding-top: 20px;">
                    <!-- <i class="icon-user"></i> -->
                    <i class="layui-icon layui-icon-friends" style="font-size: 30px; color: #CCE0C7;"></i>
                </div>
                <div class="span10" style="line-height: 30px;">
                    <div>
                        <span>用户</span>
                        <span id="userAccount"></span>
                    </div>
                   <div>
                        <span>您还不是会员</span>
                        <button class="btn btn-primary" onclick="page.openMember()">立即开通</button>
                   </div>
                </div>
            </div>
            <div style="padding: 15px;">
                <div style="background: #D6E4CD;padding: 10px;">您的会员期限已到期，为了不影响您的正常使用，请及时续费</div>
                <div style="background: #D6E4CD;padding: 10px;margin-top: 10px;">会员权益：1、找货方便；2、可以上传自家现货库存到首页</div>
            </div>
        </div>
        <div id="memberBox" style="display: none;">
            <div class="row-fluid" style="padding-top: 10px;">
                <div class="span2" style="text-align: center;">
                    <i class="layui-icon layui-icon-friends" style="font-size: 30px; color: #E4C471;"></i>
                </div>
                <div class="span10">
                    <div>
                        <span>尊敬的年费会员</span>
                        <span id="memberAccount"></span>
                    </div>
                   <div>
                        <span>会员到期时间：</span>
                        <span id="expirationTime"></span>
                   </div>
                </div>
            </div>
            <div style="margin: 15px;">
                <div style="background: #D6E4CD;padding: 10px;">您现在可以随意找货，电话直接联系，也可以联系客服上传自家库存，也可以联系客服投诉虚假现货资源</div>
            </div>

            <div style="margin: 10px;">
                <div class="row-fluid opStatistics">
                    <div class="span6">
                        <span>上传库存次数：</span>
                        <span id="uploadStockNum">0</span>
                    </div>
                    <div class="span6">
                        <span>询价点击次数：</span>
                        <span id="inquiriesNum">0</span>
                    </div>
                </div>
                <div class="row-fluid opStatistics">
                    <div class="span6">
                        <span>投诉次数：</span>
                        <span id="">0</span>
                    </div>
                    <div class="span6">
                        <span>被投诉次数：</span>
                        <span id="complainedNum">0</span>
                    </div>
                </div>
            </div>
        </div>

        <div style="text-align: center;">
            <button class="btn btn-primary" style="width: 60%;" id="editCompanyInfoBtn" onclick="page.editCompanyInfo()">编辑公司信息</button>
            <button class="btn btn-primary" style="width: 60%;margin-top: 10px;" id="uploadInventory" onclick="page.uploadInventory()">上传库存</button>
        </div>
    </div>
    <div id="kefuBox" style="padding: 20px;display: none;">
        <div style="text-align: center;font-weight: bold;padding: 10px;font-size: 20px;">
            <span>客服电话：</span>
            <span>13788932357</span>
        </div>
        <button class="btn" onclick="page.showInfo()">返回</button>
    </div>

    <div id="companyBox" style="padding: 20px;display: none;">
        <div>
            <div class="companyInfoBox">
                <label>名称：</label>
                <input id="name" readonly unselectable="on" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>简称：</label>
                <input id="abbName" readonly unselectable="on" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>联系人：</label>
                <input id="linkman" readonly unselectable="on" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>电话：</label>
                <input id="phone" readonly unselectable="on" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>业务经理1：</label>
                <input id="bizManager1" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>业务经理2：</label>
                <input id="bizManager2" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>业务经理3：</label>
                <input id="bizManager3" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>传真：</label>
                <input id="fax" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>省份：</label>
                <input id="province" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>开户银行：</label>
                <input id="bank" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>邮政编码：</label>
                <input id="postal_code" type="text" class="input-small" placeholder="">
            </div>
            <div class="companyInfoBox">
                <label>通信地址：</label>
                <input id="mailing_address" type="text" class="input-small" placeholder="">
            </div>
            <div class="row-fluid" style="margin-top: 20px;">
                <div class="span6">
                    <button type="button" class="btn btn-primary"
                            style="width: 90%;" id="saveBtn" onclick="page.saveCompanyInfo()">保存</button>
                </div>
                <div class="span6">
                    <button type="button" class="btn" style="width: 90%;"
                            onclick="page.showInfo()">返回</button>
                </div>
            </div>
        </div>

    </div>

    <div id="uploadBox" style="padding: 20px;display: none;">
        <p style="text-align: center;font-weight: bold;">现货网--上传库存</p>
        <div class="row-fluid" style="margin-top: 20px;">
            <div class="span6">
                <input style="width: 90%;" type="file" name="" id="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel">
            </div>
            <div class="span3">
                <button class="btn btn-primary" onclick="page.upload()">上传</button>
            </div>
            <div class="span3">
                <a href="./template.xlsx"><button class="btn btn-primary">模板下载</button></a>
            </div>
        </div>
        <div style="margin: 10px auto;">
            <video src="./video.mp4" controls width="100%" id="video">
                你的浏览器版本太低,不支持播放视频，请升级到更高版本！
            </video>
        </div>
        <button class="btn" onclick="page.showInfo()">返回</button>
    </div>
    <script type="text/javascript">
        var company=null,
            layer;
        layui.use(['layer'], function(){
            layer = layui.layer
            $(document).on('keydown', function(ev){
                if(ev.keyCode==27){
                    var index = parent.layer.getFrameIndex(window.name)
                    parent.layer.close(index)
                }
            })
        })

        var page = {
            memberInfo: function(){
                api.memberInfo({},function(res){
                    if(res.code==200){
                        Cookie.set('level',res.data.level)
                        if(Cookie.get('level')==0){
                            $("#userBox").show()
                            $("#userAccount").text(res.data.phone)
                        } else{
                            $("#memberBox").show()
                            $("#memberAccount").text(res.data.phone)
                            $("#expirationTime").text(res.data.expirationTime)
                            $("#inquiriesNum").text(res.data.inquiriesNum)
                            $("#complainedNum").text(res.data.complainedNum)
                            $("#uploadStockNum").text(res.data.uploadStockNum)
                            $("#onlineDeviceNum").text(res.data.onlineDeviceNum)
                        }
                    }
                })
            },
            openMember: function(){
                $("#kefuBox").show()
                $("#infoBox").hide()
            },
            showInfo: function(){
                $("#infoBox").show()
                $("#kefuBox").hide()
                $("#companyBox").hide()
                $("#uploadBox").hide()
                parent.$(".layui-layer-title")[0].innerText = "会员状态"

                try{
                    $("#video")[0].pause()
                } catch(e){

                }
            },
            editCompanyInfo: function(){
                console.log(Cookie.get('level'))
                if(Cookie.get('level')==0){
                    layer.tips('您还不是会员，请开通会员享受权益。', '#editCompanyInfoBtn', {
                        tips: [1, '#3595CC'],
                        time: 2000
                    })
                } else {
                    this.companyInfo()
                }
            },
            companyInfo: function(){
                api.companyInfo({},function(res){
                    if(res.code==200){
                        company = res.data
                        $("#name").val(company.name)
                        $("#abbName").val(company.abbName)
                        $("#bank").val(company.bank)
                        $("#bizManager1").val(company.bizManager1)
                        $("#bizManager2").val(company.bizManager2)
                        $("#bizManager3").val(company.bizManager3)
                        $("#fax").val(company.fax)
                        $("#linkman").val(company.linkman)
                        $("#mailing_address").val(company.mailing_address)
                        $("#phone").val(company.phone)
                        $("#postal_code").val(company.postal_code)
                        $("#province").val(company.province)

                        parent.$(".layui-layer-title")[0].innerText = "编辑公司信息"
                        $("#companyBox").show()
                        $("#infoBox").hide()
                    } else {
                        layer.msg(res.msg)
                        return
                    }
                })
            },
            saveCompanyInfo: function(){
                var post = {
                    name: $("#name").val(),
                    abbName: $("#abbName").val(),
                    bank: $("#bank").val(),
                    bizManager1: $("#bizManager1").val(),
                    bizManager2: $("#bizManager2").val(),
                    bizManager3: $("#bizManager3").val(),
                    fax: $("#fax").val(),
                    linkman: $("#linkman").val(),
                    mailing_address: $("#mailing_address").val(),
                    phone: $("#phone").val(),
                    postal_code: $("#postal_code").val(),
                    province: $("#province").val()
                }
                if(post.name==''){
                    layer.msg('公司名称不能为空')
                    return
                }
                if(post.abbName==''){
                    layer.msg('简称不能为空')
                    return
                }
                if(post.abbName.length>5){
                    layer.msg('简称不能超过5个汉字')
                    return
                }
                api.saveCompanyInfo(JSON.stringify(post),function(res){
                    if(res.code==200){
                        layer.msg('保存成功')
                        page.showInfo()
                    } else{
                        layer.msg(res.msg)
                    }
                })

            },
            uploadInventory: function(){
                if(Cookie.get('level')==0){
                    layer.tips('您还不是会员，请开通会员享受权益。', '#uploadInventory', {
                        tips: [1, '#3595CC'],
                        time: 2000
                    })
                } else {
                    parent.$(".layui-layer-title")[0].innerText = "上传库存"
                    $("#uploadBox").show()
                    $("#infoBox").hide()
                }
            },
            upload: function(){
                if($("#file").val()==''){
                    layer.msg('请选择要上传的文件')
                    return
                }
                var file = $("#file")[0].files[0]
                // console.log(file.type)
                if(file.type!='application/vnd.ms-excel'&&file.type!='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'){
                    layer.msg('请选择正确的文件')
                    return
                }
                var formData = new FormData()
                formData.append("file",file)
                api.uploadInventory(formData,function(res){
                    if(res.code==200){
                        layer.msg('保存成功')
                        $("#file").val('')
                        parent.statistics()
                    } else{
                        layer.msg(res.msg)
                        // layer.msg('保存失败，请检查数据是否正确')
                    }
                })
            }
        }
        page.memberInfo()
    </script>
</body>

</html>
